package com.tucc.hello.leetcode.no1_400.no1_200.no1_20.no11_20.no17;

import java.util.*;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.letterCombinations("22"));
    }

    String[] letterMapper = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    public List<String> letterCombinations(String digits) {
        List<String>  result = new ArrayList<>();
        if(digits.length() > 0) {
            listProbability(digits, 0, 0, "", result);
        }
        return result;
    }

    public void listProbability(String digits, int curIndex, int curLetterIndex,
                                String resultLetter, List<String> result){
        if(curIndex == digits.length()){
            result.add(resultLetter);
        }
        else {
            char curCh = digits.charAt(curIndex);
            String letters = letterMapper[curCh - '2'];
            if (curLetterIndex < letters.length()) {
                listProbability(digits, curIndex + 1, 0, resultLetter + letters.charAt(curLetterIndex),
                        result);
                listProbability(digits, curIndex, curLetterIndex + 1, resultLetter, result);
            }
        }
    }
}
